package com.sdy.usercenter.mq.service;

import com.sdy.common.utils.DateUtil;
import com.sdy.usercenter.biz.constants.MqConstants;
import com.sdy.usercenter.biz.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class UsercenterMsgFacade {
    @Autowired
    private SysLogService sysLogService;

    /**
     * msg: optUserId ## opTime ## ip ## content
     */
    public void consumeOpLog(String msg) {
        try {
            String[] msgs = msg.split(MqConstants.SEP_TOKEN);
            Integer type = Integer.valueOf(msgs[0]);
            Integer userId = Integer.valueOf(msgs[1]);
            Date opDate = DateUtil.getDate(msgs[2], DateUtil.DATETIME_FORMAT);
            sysLogService.logCommonInfo(type, userId, opDate, msgs[3], msgs[4]);
        } catch (Exception e) {
            log.error("Comsume oplog error!", e);
        }
    }
}
